import { faker } from "@faker-js/faker";
import { supabase } from "../utils/supabase.js";

const subjectList = ["Math", "English", "Science", "History", "Geography"];

export function generateScore() {
  const score = faker.number.int({ min: 60, max: 100 });
  const semesterYear = faker.number.int({ min: 2000, max: 2025 });
  const semesterSeason = faker.helpers.arrayElement(["Spring", "Autumn"]);
  const subject = faker.helpers.arrayElement(subjectList);
  const student_id = faker.number.int({ min: 32, max: 41 });
  return {
    score,
    semesterYear,
    semesterSeason,
    subject,
    student_id,
  };
}

export function generateScores(count = 5) {
  return new Array(count).fill(0).map(() => generateScore());
}

export async function insertScores(count = 5) {
  const students = generateScores(count); //五条学生分数
  const { data, error } = await supabase
    .from("score")
    .insert(students) //插入
    .select();
  if (error) {
    console.log(error.message);
    return;
  }
  return data;
}
